package com.rongshu.view.penpal.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.rongshu.eventbus.SearchPenpalArticleMode;
import com.rongshu.utils.Constant;
import com.rongshu.view.penpal.fragment.Penpal_SearchArticleListFragment;

/**
 * created by zhengweis on 2018/11/1.
 * description：
 */
public class PenpalSearchArticleTypePageAdapter extends FragmentStatePagerAdapter {
    String[] titles = {"文章", "帖子"};
    private SearchPenpalArticleMode mode;

    public PenpalSearchArticleTypePageAdapter(FragmentManager fm, SearchPenpalArticleMode mode) {
        super(fm);
        this.mode = mode;
    }

    @Override
    public Fragment getItem(int position) {
        return createForNoExpand(position);
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    private Fragment createForNoExpand(int position) {
        Penpal_SearchArticleListFragment fragment = null;
        Bundle bundle = new Bundle();
        bundle.putSerializable(Constant.INTENT_DATA, mode);
        switch (position) {
            case 0://文章
                bundle.putInt("type", Constant.ARTICLE);
                fragment = new Penpal_SearchArticleListFragment();
                break;
            case 1://帖子
                bundle.putInt("type", Constant.POST);
                fragment = new Penpal_SearchArticleListFragment();
                break;
        }
        fragment.setArguments(bundle);
        return fragment;
    }
}